package com.xneure.utils.bean;

import javax.servlet.http.HttpServletRequest;

public class RequestInfo {

	private static String[] keywords = { "Android", "iPhone", "Wechat", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
	private String browser;
	private String protocol;
	private String addr;
	private String host;
	private int port;
	private String user;

	public RequestInfo(HttpServletRequest req) {
		this.browser = req.getHeader("user-agent");
		this.protocol = req.getProtocol();
		this.addr = req.getRemoteAddr();
		this.host = req.getRemoteHost();
		this.port = req.getRemotePort();
		this.user = req.getRemoteUser();
	}

	public String getBrowser() {
		return browser;
	}

	public String getProtocol() {
		return protocol;
	}

	public String getAddr() {
		return addr;
	}

	public String getHost() {
		return host;
	}

	public int getPort() {
		return port;
	}

	public String getUser() {
		return user;
	}

	public boolean isMobile() {
		for (String item : keywords) {
			if (browser.contains(item)) {
				return true;
			}
		}
		return false;
	}

	public static boolean isMobile(HttpServletRequest request) {
		String agent = request.getHeader("user-agent");
		for (String item : keywords) {
			if (agent.contains(item)) {
				return true;
			}
		}
		return false;
	}
}
